package com.aegean.MonitorExamSYS.examinee.action;

import java.io.File;
import java.io.FileInputStream;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.hibernate.Hibernate;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExamSYS.examinee.business.ExamineeBusiness;
import com.aegean.MonitorExaxSYS.model.ExamineeValue;
import com.aegean.MonitorExaxSYS.model.component.Photo;
import com.opensymphony.xwork2.ActionSupport;
@Controller("UserUpdateInfo")
@Scope("prototype")
public class UserUpdateInfo extends ActionSupport {
	@Resource
	ExamineeBusiness business;
	private ExamineeValue user;
	private File photo;
	private String photoFileName;
	private String photoContentType;

	public ExamineeValue getUser() {
		return user;
	}

	public void setUser(ExamineeValue user) {
		this.user = user;
	}

	public File getPhoto() {
		return photo;
	}

	public void setPhoto(File photo) {
		this.photo = photo;
	}

	public String getPhotoFileName() {
		return photoFileName;
	}

	public void setPhotoFileName(String photoFileName) {
		this.photoFileName = photoFileName;
	}

	public String getPhotoContentType() {
		return photoContentType;
	}

	public void setPhotoContentType(String photoContentType) {
		this.photoContentType = photoContentType;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		System.out.println("11");
		HttpSession session=ServletActionContext.getRequest().getSession();
		ExamineeValue one=(ExamineeValue)session.getAttribute("UserLogin");
		System.out.println("22");
		int Customer_Id=one.getUser_Id();
		if(photo==null||photo.length()==0){
			System.out.println("33");
			user=business.updateUser(Customer_Id, user,null );
		}else{
			System.out.println("44");
			Photo p=new Photo();
			p.setPhoto(Hibernate.createBlob(new FileInputStream(photo)));
			p.setPhoto_Name(photoFileName);
			p.setPhoto_Type(photoContentType);
			System.out.println("55");
			user=business.updateUser(Customer_Id, user,p);
		}
		System.out.println("66");
		session.setAttribute("UserLogin",user);
		return SUCCESS;
	}
}
